/*
 * program.h -- this file is part of mISPL.
 * Copyright (C) 2011 Christian Krause
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#ifndef PROGRAM_H_
#define PROGRAM_H_

#include "common.h"
#include "block.h"

/*** Program instructions ***/
#define SET 0
#define COP 1
#define SWP 2
#define SIG 3
#define ABS 4
#define ADD 5
#define SUB 6
#define MUL 7
#define DIV 8
#define MOD 9
#define POW 10
#define ROO 11
#define SKE 12
#define SKN 13
#define SKL 14
#define SKG 15
#define LPB 16
#define LPE 17

/*** Instruction count ***/
#define INSTRUCTION_COUNT (LPE+1)

/*** Instruction names ***/
static const char INSTRUCTION_NAMES[][4] =
	{ "SET", "COP", "SWP", "SIG", "ABS", "ADD", "SUB", "MUL", "DIV",
	  "MOD", "POW", "ROO", "SKE", "SKN", "SKL", "SKG", "LPB", "LPE" };

/*** Maximum program parameters ***/
#define MAX_PROGRAM_REGISTERS 16
#define MAX_PROGRAM_LENGTH 16

/*** Command data type ***/
typedef u_short command_t;

/*** Program data type ***/
typedef struct __program __program_s;
typedef __program_s* program_t;
struct __program {
	u_char registers;
	u_char length;
	command_t commands[MAX_PROGRAM_LENGTH];
};

/*** Program functions ***/
program_t	program_init(u_char registers, u_char length);
program_t	program_init_rand(u_char registers, u_char length);
void		program_fill_rand(program_t program);
void		program_clear(program_t program);
void		program_print(program_t program);
void		program_simplify(program_t program);
program_t	program_copy(program_t program);
sequence_t	program_exec(program_t program, block_t history, int maxbits);

#endif /* PROGRAM_H_ */
